package edu.towson.cosc.cosc455.mlam4.compiler;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;



public class MyCompiler {

	public static String token;
	public static String lolFile;
    static MyLexicalAnalyzer Lexer;
    static MySyntaxAnalyzer parser;
    static MySemanticAnalyzer generator;
    public static ArrayList<String> validTokens;
    public static ArrayList<String> parseTree;
    
    
    public static void main(String[] args){
    	//perform initial initialization of variables
    	token = "";
    	lolFile = "";
    	//create list for all valid Lexical Tokens
    	validTokens=new ArrayList<String>();
    	validTokens.add(LexicalTokens.DOC_BEGIN);
    	validTokens.add(LexicalTokens.DOC_END);
    	validTokens.add(LexicalTokens.COMMENT_BEGIN);
    	validTokens.add(LexicalTokens.COMMENT_END);
    	validTokens.add(LexicalTokens.HEAD_BEGIN);
    	validTokens.add(LexicalTokens.HEAD_END);
    	validTokens.add(LexicalTokens.TITLE_BEGIN);
    	validTokens.add(LexicalTokens.TITLE_END);
    	validTokens.add(LexicalTokens.PARAGRAPH_BEGIN);
    	validTokens.add(LexicalTokens.PARAGRAPH_END);
    	validTokens.add(LexicalTokens.BOLD_BEGIN);
    	validTokens.add(LexicalTokens.BOLD_END);
    	validTokens.add(LexicalTokens.ITALICS_BEGIN);
    	validTokens.add(LexicalTokens.ITALICS_END);
    	validTokens.add(LexicalTokens.LIST_BEGIN);
    	validTokens.add(LexicalTokens.LIST_END);
    	validTokens.add(LexicalTokens.ITEM_BEGIN);
    	validTokens.add(LexicalTokens.ITEM_END);
    	validTokens.add(LexicalTokens.NEWLINE);
    	validTokens.add(LexicalTokens.SOUNDS_BEGIN);
    	validTokens.add(LexicalTokens.SOUNDS_END);
    	validTokens.add(LexicalTokens.VIDEO_BEGIN);
    	validTokens.add(LexicalTokens.VIDEO_END);
    	validTokens.add(LexicalTokens.VARIABLE_DEFINE_BEGIN);
    	validTokens.add(LexicalTokens.VARIABLE_DEFINE_MIDDLE);
    	validTokens.add(LexicalTokens.VARIABLE_DEFINE_END);
    	validTokens.add(LexicalTokens.VARIABLE_USE_BEGIN);
    	validTokens.add(LexicalTokens.VARIABLE_USE_END);
    	
    	//check for 1 arguemtn
    	if (args.length != 1){
    		System.err.println("ERROR! No argument found");
    		System.exit(0);
    	}
        
        
        
    	File file= new File (args[0]);
    	try{
        	Scanner scan = new Scanner(file);
        	while (scan.hasNextLine()){
        		lolFile+= scan.nextLine() + " ";
        	}
    	}catch (FileNotFoundException e){
        	e.printStackTrace();
    	}

    	String extension = "";
    	String filename=file.getName();
    	int i=filename.lastIndexOf('.');
        if(i>0){
            extension=filename.substring(i+1);
    }
        if (!extension.equals("lol")){
            System.err.println("ERROR, Incorrect File Type. File Must be Type .lol");
    }

        parseTree = new ArrayList<String>();
        
        Lexer=new MyLexicalAnalyzer();
        Lexer.getNextToken();
       
        parser= new MySyntaxAnalyzer();
        parser.lolcode();
       
        generator = new MySemanticAnalyzer();
        generator.convert();
        
    	generator.printTrees();
        
    	
    	
    	
    	
    }



}

